package com.scetoop.bank;

import java.util.ArrayList;
import java.util.List;

public class Bank {
    private static Bank instance;
    private List<Customer> customers;
//    private Customer[] customers;
//    private int numberOfCustomers;
//    private static Bank instance;

//    public Bank(){
//        customers = new Customer[100];
//        numberOfCustomers = 0;
//    }
//      private Bank(){
//            customers = new Customer[100];
//            numberOfCustomers = 0;
//      }
//     public static Bank getBanking() {
//        if (instance == null) {
//            instance = new Bank();
//        }
//        return instance;
//     }
//    public void addCustomer(String f, String l){
////        this.firstName = f;
////        this.lastName = l;
////        Customer customer = customers.
//        Customer customer = new Customer(f,l);
//        if(numberOfCustomers < customers.length){
//            customers[numberOfCustomers] = customer;
//            numberOfCustomers++;
//        }
//    }
//      public int getNumOfCustomers(){
//            return numberOfCustomers;
//      }
//    public Customer getCustomer(int index){
//        if(index >= 0&&index <numberOfCustomers){
//            return customers[index];
//        }
//        return null;
//    }
// 修改构造器
//public Bank() {
//    customers = new ArrayList<>();
//}
private Bank() {
    customers = new ArrayList<>();
}

    // 添加getBanking方法实现单例模式
    public static Bank getBanking() {
        if (instance == null) {
            instance = new Bank();
        }
        return instance;
    }

    // 修改addCustomer方法
    public void addCustomer(String f, String l) {
        customers.add(new Customer(f, l));
    }

    // 修改getCustomer方法
    public Customer getCustomer(int index) {
        return customers.get(index);
    }

    // 修改getNumOfCustomers方法
    public int getNumOfCustomers() {
        return customers.size();
    }
}
